home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
bix03.arc
/
ZAP.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1986-08-04
|
7KB
|
307 lines
(*ZAP.PAS/Turbo/MS/PCDOS/IBM & Clones - Browse & Patch files in Hex & Ascii.
***moved here from Turbo #1470 due to its size. - Jim Keohane
Here's a little quickie I use when I want to see the Ascii and hex
contents of a file. You compile to .COM file and type "zap filename.ext".
You get prompted for a block number starting with zero (1st block). You
will be shown the contents of the selected 512 byte block on your screen.
At this point ESC will get you back to the "Enter Block No..." and
hitting F10 will make the program end. You can also EDIT the block by
skipping around (use arrows on numeric keypad) and typing over any char
you want to change. You can type most normal Ascii characters and any
unusual ones can be entered in hex. The updated block will not be written
back to the file unless you hit F1.
This was a quick-and-dirty I put together so play with the code and add
some improvements. One problem is that if you rewrite the last block on
the file I set the new file length to a multiple of 512. This enables you
to add some info to most files but it should be a lot cleaner. Perhaps
one of you could fix this. The "dump" of the current block shows 64 chars
across. First is Ascii and underneath is the hex...
A
4
1
The block number shows at top left. If you type a block number that's
past the end of the file the prompt will repeat. - Jim
*)
Program zap;
Type
RegType = record case integer of
0:(Ax,Bx,Cx,Dx,Bp,Si,Di,Ds,Es,Flags:integer);
1:(Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh:byte);
2:(words:array[0..9] of integer);
3:(bytes:array[0..7] of byte)
end;
type block = array[0..7] of record row:array[0..63] of byte end;
str3=string[3];
const hex:array[0..15] of char = '0123456789ABCDEF';
hexs:string[15]='123456789ABCDEF';
var f:file of block;
blk:block;
c:char;
blkno,x,y,z:integer;
function three(i:integer):str3;
begin three:=hex[hi(i)]+hex[lo(i) shr 4] + hex[lo(i) and $f] end;
procedure manager(which:byte);
const LeftArrow='L';RightArrow='R';Home='H';Endd='E';
UpArrow='u';DownArrow='d';
PgUp='U';PgDn='D';Ins='+';Del='-';BackTab='B';ForwardTab='F';
numpad:string[13]='HuU?L?R?EdD+-';
cnumpad:string[18]='LREDH????????????U';
toprow:string[12]='1234567890-=';
qwerty:string[35]='qwertyuiop????asdfghjkl?????zxcvbnm';
var ch:char;
begin
ch:='?';
case which of
16..25,30..38,44..50,120..131:
begin {Alt keys}
if which>=120 then ch:=toprow[which-119] else ch:=qwerty[which-15];
case ch of
'a':;
'b':;
'c':;
'd':;
'e':;
'f':;
'g':;
'h':;
'i':;
'j':;
'k':;
'l':;
'm':;
'n':;
'o':;
'p':;
'q':;
'r':;
's':;
't':;
'u':;
'v':;
'x':;
'y':;
'z':;
'0':;
'1':;
'2':;
'3':;
'4':;
'5':;
'6':;
'7':;
'8':;
'9':;
end;
end;
104..113:case which-103 of {alt function keys}
1:;
2:;
3:;
4:;
5:;
6:;
7:;
8:;
9:;
10:;
end;
59..68:case which-58 of {function keys}
1:begin seek(f,blkno);write(f,blk) end;
2:;
3:;
4:;
5:;
6:;
7:;
8:;
9:;
10:begin close(f); halt end;
end;
84..93:case which-83 of {shift function keys}
1:;
2:;
3:;
4:;
5:;
6:;
7:;
8:;
9:;
10:;
end;
94..103:case which-93 of {ctrl function keys}
1:;
2:;
3:;
4:;
5:;
6:;
7:;
8:;
9:;
10:;
end;
151..157,160..162,164..176:
case chr(which-54) of {ctrl keys}
'a':;
'b':;
{ctrl-c or ctrl-break is not intercepted}
'd':;
'e':;
'f':;
'g':;
{note: ctrl-h is taken to be backspace}
'i':;
'j':;
'k':;
'l':;
{note: ctrl-m is taken to be Enter [CR]}
'n':;
'o':;
'p':;
'q':;
'r':;
's':;
't':;
'u':;
'v':;
'x':;
'y':;
'z':;
end;
15,71..73,75,
77,79..83,159:
begin
if which=15 then ch:=BackTab else
if which=159 then ch:=ForwardTab else
ch:=numpad[which-70];
case ch of {numeric key pad keys}
BackTab:;
ForwardTab:;
Home:;
UpArrow:begin y:=pred(24+y*3+z) mod 24;z:=y mod 3;y:=y div 3 end;
PgUp:;
LeftArrow:if x=0 then x:=63 else x:=pred(x);
RightArrow:if x=63 then x:=0 else x:=succ(x);
Endd:;
DownArrow:begin y:=succ(y*3+z) mod 24;z:=y mod 3;y:=y div 3 end;
PgDn:;
Ins:;
Del:;
end;
end;
115..119,132:
begin
case cnumpad[which-114] of {ctrl-numeric key pad keys}
LeftArrow:;
RightArrow:;
Endd:;
PgDn:;
Home:;
PgUp:;
end;
end;
end;
gotoxy(x+7,1+y*3+z)
end;
function kbchar:char;
var r:regtype;
begin
r.ah:=$0b;
msdos(r);
if r.al = 0 then kbchar:=#0
else begin
r.ah:=$07;
msdos(r);
if r.al<>0 then
if r.al in [8,13,27,32..127] then kbchar:=chr(r.al)
else begin manager(r.al+150);kbchar:=#0 end
else
begin
r.ah:=$07;
msdos(r);
manager(r.al);
kbchar:=#0
end;
end;
end;
procedure showchar;
var zz:integer;
begin
for zz:=0 to 2 do
begin
gotoxy(x+7,1+y*3+zz);
case zz of
0:write(chr(blk[y].row[x]));
1:write(hex[blk[y].row[x] shr 4]);
2:write(hex[blk[y].row[x] and 15])
end
end;
gotoxy(x+7,1+y*3+z)
end;
procedure showblk;
begin
clrscr;
gotoxy(72,1);
write('#',BlkNo);
for y:=0 to 7 do
begin
gotoxy(1,1+y*3);
writeln(three(y*64));
writeln('to');
writeln(three(y*64+63));
for x:=0 to 63 do showchar;
end
end;
procedure getblk;
begin
clrscr;
repeat
gotoxy(1,1);
write('Block #?....');
readln(BlkNo);
gotoxy(1,1);
write(' ');
{$I-}
seek(f,BlkNo);
read(f,Blk)
{$I+}
until ioresult=0
end;
procedure editblk;
begin
x:=0;y:=0;z:=0;
repeat
gotoxy(x+7,1+y*3+z);
repeat c:=kbchar until c<>#0;
if c<>^[ then
case z of
0:blk[y].row[x]:=ord(c);
1:blk[y].row[x]:=(blk[y].row[x] and 15) or (pos(upcase(c),hexs) shl 4);
2:blk[y].row[x]:=(blk[y].row[x] and 240) or pos(upcase(c),hexs)
end;
Showchar
until c=^[
end;
begin
assign(f,paramstr(1));
reset(f);
repeat
clrscr;
getblk;
showblk;
editblk;
until false;
end.